<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'header.php'?>
	<style>
		a {
			text-decoration: none;
		}
		a:hover {
			text-decoration: none;
		}
		.img {
			display: flex;
			flex-wrap: wrap;
		}
		.img img{
			width: 210px;
			height: 210px;
			object-fit: cover;
			margin: 15px;
		}
		.form-control {
			height: auto;
		}
		#cboxClose{
			text-indent: 0;
			font-size: 50px;
			font-weight: bold;
			margin-top: 10px;
			color: red;
		}
		.ace-thumbnails li {
			margin: 0 10px;
		}
    </style>
	<div class="page-header">
		<h1><?=$announceInfo ? '编辑校园公告' : '发布校园公告'?></h1>
	</div>

	<div class="col-xs-12">
		<form class="form-horizontal" id="classes-form">
			<input type="hidden" name="id" value="<?=$announceInfo['id']?>" />
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">公告标题：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="announce_title" value="<?=$announceInfo['announce_title']?>" placeholder="请填写公告标题"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">公告类型：</label>
				<div class="col-sm-6">
					<select class="form-control" name="announce_type">
						<option value="0" <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_TEXT ? 'selected' : '' ?> >文本公告</option>
						<option value="1" <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_LINK ? 'selected' : '' ?> >外部链接</option>
					</select>
				</div>
			</div>
			<div class="form-group <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_LINK ? '' : 'hide' ?>" id="link-div">
				<label class="col-sm-3 control-label no-padding-right">外部链接地址：</label>
				<div class="col-sm-6">
					<input class="form-control" type="text" name="external_link"" value="<?= isset($announceInfo['external_link']) ? $announceInfo['external_link'] : '' ?>" placeholder="请填写外部链接地址"/>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label no-padding-right">是否置顶：</label>
				<div class="col-sm-6">
					<select class="form-control" name="is_top">
						<option value="0" <?= !isset($announceInfo['is_top']) || $announceInfo['is_top'] == 0  ? 'selected' : '' ?>>否</option>
						<option value="1" <?= isset($announceInfo['is_top']) && $announceInfo['is_top'] == 1  ? 'selected' : '' ?> style="color: red">是</option>
					</select>
				</div>
			</div>
			<div class="clearfix <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_LINK  ? '' : 'hide' ?>" id="submit-top">
				<div class="col-md-offset-3 col-md-9">
					<a class="btn btn-info submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</a>
				</div>
			</div>
			<div <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_LINK  ? 'style="visibility:hidden;"' : '' ?> class="form-group" id="content-div">
				<label class="col-sm-3 control-label no-padding-right">公告内容：</label>
				<div class="col-sm-6">
					<textarea class="pd0" id="content" name="announce_content" style="height: 400px;width: 100%"><?=urldecode($announceInfo['announce_content'])?></textarea>
				</div>
			</div>
			<div class="clearfix <?= isset($announceInfo['announce_type']) && $announceInfo['announce_type'] == ANNOUNCE_TYPE_LINK  ? 'hide' : '' ?>" id="submit-bottom">
				<div class="col-md-offset-3 col-md-9">
					<a class="btn btn-info submit">
						<i class="ace-icon fa fa-check"></i> 提交
					</a>
				</div>
			</div>
		</form>
	</div>
<?php require VIEWPATH. ADMIN_DIR. DIRECTORY_SEPARATOR. 'footer.php'?>
<!-- 百度编辑器 -->
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.config.js"></script>
<script src="<?=$staticAdminUrl?>assets/ueditor/ueditor.all.js"></script>
<script type="text/javascript">
	$(function(){
		// 初始化编辑器
		var ue = UE.getEditor('content');
		$(".submit").click(function() {
			var id = $("[name=id]").val();
			var announceTitle = $("[name=announce_title]").val();
			var announceContent = $("[name=announce_content]").val();
			var announceType = $("[name=announce_type]").val();
			var externalLink = $("[name=external_link]").val();
			var url = "<?=admin_url('contents/save_announce_action')?>";
			var isTop = $("[name=is_top]").val();
			var data = {
				"id": id,
				"announce_title": announceTitle,
				"announce_content": announceContent,
				"announce_type": announceType,
				'external_link': externalLink,
				'is_top': isTop
			};
			ajax_post(url, data, function() {
				window.location.href = "<?=admin_url('contents/announce')?>";
			});
		});
		// 通知类型切换
		$("[name=announce_type]").change(function(){
			if($(this).val() == 1) {
				$('#link-div').removeClass("hide");
				$('#content-div').css('visibility', 'hidden');
				$('#img-div').addClass("hide");
				$("#submit-top").removeClass("hide");
				$("#submit-bottom").addClass("hide");
			} else {
				$('#link-div').addClass("hide");
				$('#content-div').css('visibility', 'visible')
				$('#img-div').removeClass("hide");
				$("#submit-top").addClass("hide");
				$("#submit-bottom").removeClass("hide");
			}
		})
	})
</script>